﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TreeView_binding
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = data_;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Node child = new InnerNode(textBox1.Text);
            InnerNode node = treeView1.SelectedItem as InnerNode;
            if (node != null)
            {
                node.Children.Add(child);
            }
            else
            {
                data_.Tree.Add(child);
            }      
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            Node child = new LeafNode(textBox1.Text);
            InnerNode node = treeView1.SelectedItem as InnerNode;
            if ( node != null ) {
              node.Children.Add(child);
            } else {
              data_.Tree.Add(child);
            }      
        }

        private BindData data_ = new BindData();
    }
}
